package springboot.study.project.util.common;


import springboot.study.project.common.Result;
import springboot.study.project.common.ResultEnum;
import springboot.study.project.common.UserException;

public class ResultUtil {
    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    public static Result success() {
        return success(null);
    }

    public static Result failure(String errMsg) {
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getCode());
        result.setMsg(errMsg);
        return result;
    }

    public static Result failure(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    public static Result failure(ResultEnum resultEnum) {
        return failure(resultEnum.getCode(),resultEnum.getMsg());
    }
    public static Result failure(UserException userException) {
        return failure(userException.getCode(),userException.getMessage());
    }
}
